<?php

namespace mbilling\BillingBundle\Model;

use Doctrine\ORM\EntityManager;
use mbilling\BillingBundle\Entity\bonusesTable;


Class BonusesTableModel
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

    public function findAll()
    {
        $bonuses = $this->em->getRepository('BillingBundle:bonusesTable')->findAll();
        return $bonuses;
    }
    
    public function findByPK($bonus_id)
    {
        $bonus = $this->em->find('BillingBundle:bonusesTable', $bonus_id);
        return $bonus;
    }

    public function findByUserIdAndActive($user_id, $active)
    {
        $bonuses = $this->em->getRepository('BillingBundle:bonusesTable')->findBy(array('used_at' => NULL, 'user_id' => $user_id, 'is_active' => $active));
        return $bonuses;
    }

    public function create($oEntity)
    {
        $this->em->persist($oEntity);
        $this->em->flush();
    }

    public function removeByPK($bonus_id)
    {
        $bonus = $this->em->find('BillingBundle:bonusesTable', $bonus_id);
        $this->em->remove($bonus);
        $this->em->flush();
    }

    public function checkByPK($bonus_id)
    {
        $bonus = $this->em->getRepository('BillingBundle:bonusesTable')->findOneBy(array('bonus_id' => $bonus_id));
        if (isset($bonus))
            return true;
        else
            return false;
    }
}
?>
